package com.ljf.eslab.lab.controller;

import java.util.Arrays;
import java.util.Map;

import com.ljf.eslab.lab.entity.TeacherEntity;
import com.ljf.eslab.lab.service.UserTokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ljf.eslab.lab.service.TeacherService;
import com.ljf.common.utils.R;



/**
 *
 *
 * @author ljf
 * @email ljf@gmail.com
 * @date 2021-05-28 09:13:00
 */
@RestController
@Slf4j
@RequestMapping("lab/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private UserTokenService userTokenService;
//    /**
//     * 列表
//     */
//    @RequestMapping("/list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = teacherService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }
    /**
     * 信息
     */

    @RequestMapping("/list")
    public R infoInHeader(@RequestHeader("token") String token, @RequestParam Map<String, Object> params){
        Long userID = userTokenService.getIdByToken(token);
        TeacherEntity teacher = teacherService.queryPageById(params,userID);
        log.debug("成功获取信息:{}",teacher.getRealName());
        return R.ok().put("teacher",teacher);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		TeacherEntity teacher = teacherService.getById(id);

        return R.ok().put("teacher", teacher);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TeacherEntity teacher){
		teacherService.save(teacher);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TeacherEntity teacher){
		teacherService.updateById(teacher);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		teacherService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
